package com.example.linearlayoutdemo.network.fun.network;

import com.example.linearlayoutdemo.network.auth.utils.SharedPreferencesUtil;

import okhttp3.Interceptor;
import okhttp3.Request;
import okhttp3.Response;
import java.io.IOException;

public class GlobalHeaderInterceptor implements Interceptor {
    @Override
    public Response intercept(Chain chain) throws IOException {
        // 1. 获取原始请求
        Request originalRequest = chain.request();

        // 2. 构建新请求，添加全局头
        Request newRequest = originalRequest.newBuilder()
                // 全局动态头：从本地获取 Token
                .header("Authorization", "Bearer " + SharedPreferencesUtil.getInstance(null).getUser().getToken())
                // 全局静态头：固定 App 版本
                .header("App-Version", "1.0.0")
                // 可继续添加更多全局头（如 Device-Type、Network-Type）
                .header("Device-Type", "Android")
                .header("x-api-key", "reqres-free-v1")
                .build();

        // 3. 传递新请求，继续执行
        return chain.proceed(newRequest);
    }
}
